userlist=[
         {'name':'zhangsan','id':123456787,'password':123,'money':123},
         {'name':'lisi','id':123456788,'password':123,'money':9991},
         {'name':'wangwu','id':123456789,'password':123,'money':9999}]
user=""

def mainmenu():
    print("="*12, "学员管理系统","="*14)
    print("{0:1} {1:13} {2:15}".format(" ","1.登陆", "2.余额查询"))
    print("{0:1} {1:13} {2:15}".format(" ","3.存钱","4.取钱"))
    print("{0:1} {1:13}".format(" ","5.退出"))
    key = input("请输入对应的选择:  ")
def signin():
        global user
        account = input("请您输入账号：")
        password = input("请输入密码：")
        for v in range(len(userlist)):
            if userlist[v]["id"] == account and userlist[v]['passwoddr']==password:
                user = account
                print("登陆成功")
                break
            else:
                if input("输入的账号密码有误，是否重新输入 yes/no") == "yes":
                    signin()
                    break
def savemoney():
    try:
        sunmoney = int(input("请输入存款金额："))
    except:
        print("请不要放入假钞！")
        savemoney()
        return
    for v in range(len(userlist)):
        if user == userlist[v]['id']: #调取数据库用户信息进行改写
            userlist[v]['money']+=sunmoney
            print("您成功存款{}元".format(sunmoney))
            break
def drawmoney():
    try:
        sunmoney = int(input("请输入存款金额："))
    except:
        drawmoney()
        return
    for v in range(len(userlist)):
        if user == userlist[v]['id']:
            if userlist[v]['money'] >=sunmoney: #调取数据库用户信息进行改写
                userlist[v]['money']-=sunmoney
                print("您成功存款{}元".format(sunmoney))
            break
        else:
            print("您的账户余额不足!")
            break
def ATM_BalanceInquiry():
    
    for v in range(len(userlist)):
        if user == userlist[v]['id']: #调取数据库用户信息输出
            print("您的账户余额还有{}元".format(userlist[v]['money']))
            break
def signinok():
    if user == "":
        print("请先进行登陆！")
    return not user == ""
def handle():
    key = input("请输入对应编号进行操作：")
    if key == "1":
        signin()
    elif key == "2":
        if signinok():
            ATM_BalanceInquiry()
    elif key == "3":
        if signinok():
            savemoney()
    elif key == "4":
        if signinok():
            drawmoney()
    elif key == "5":
        return
    else:
        print("无效操作，请重新输入")
    handle()
    
mainmenu()
handle()
